package com.kaibes.platform.file.client.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.kaibes.platform.file.client.db.FileMapService;
import com.kaibes.web.admin.IconBox;
import com.kaibes.web.util.WebUtils;

@Configuration
public class FileClientBoxInit {

	@Autowired
	private FileMapService fileMapService;
	
	@Bean
	public IconBox fileMapBox() {
		IconBox iconBox = new IconBox() {

            @Override
            public void update() {
                setCount(fileMapService.count());
            }
        };
        iconBox.setSort(21);
        iconBox.setName("全站文件总数");
        iconBox.setClassAppend("bg-info");
        iconBox.setIcon("ion-clipboard");
        iconBox.setHref("/admin/file/map");
        return iconBox;
	}
	
	@Bean
	public IconBox selfFileMapBox() {
		IconBox iconBox = new IconBox() {

            @Override
            public void update() {
            	Integer userId = WebUtils.getAttribute("userId");
                setCount(fileMapService.countByUserId(userId));
            }
        };
        iconBox.setSort(21);
        iconBox.setName("个人文件总数");
        iconBox.setClassAppend("bg-info");
        iconBox.setIcon("ion-clipboard");
        iconBox.setHref("/admin/file/map/self");
        return iconBox;
	}
}
